#ifndef FORM_VIEW
#define FORM_VIEW

class FormView : public View
{
public:
	// ctor/dtor with minimal args
	// The second param, id should be the template ID of a dialog in resource.rc(IDD_*).
	FormView(HINSTANCE hInst, WORD id, HWND hParent): instance(hInst), id(id), 
		View(hInst, L"FormView",hParent),
		parentHandle(hParent), x(0), y(0)
	{

	}
	~ FormView(){}

	int create()                          // create a dialog
	{
		hwnd = ::CreateDialogParam(instance, MAKEINTRESOURCE(id)  , parentHandle, dialogProcedure, (LPARAM)handler);

		return 0;
	}

	int addListener (Handler * h)
	{ 
		this->handler = h ; 
		//::SetWindowLongPtr (hwnd, GWLP_USERDATA, (LONG_PTR) handler ); 
		return 0;
	}
	int show(int cmdShow=SW_SHOWDEFAULT)
	{
		::ShowWindow(hwnd, cmdShow);
		::UpdateWindow(hwnd);
		return 0;
	}
	//HWND getHandle()                        { return handle; }; // return dialog window handle

	// setters
	void setPosition(int x, int y)          { this->x = x; this->y = y; };
	void setWidth(int w)                    { width = w; };
	void setHeight(int h)                   { height = h; };
	int setWindowPos(int x, int y, int cx, int cy)
	{
		return ::SetWindowPos(this->hwnd, 0, x, y, cx, cy, SWP_NOZORDER);
	}


private:
	//HWND handle;                            // handle to this window
	HWND parentHandle;                      // handle to parent window
	WORD id;
	int x;                                  // window position X
	int y;                                  // window position Y
	int width;                              // window width
	int height;                             // window height
	HINSTANCE instance;                     // handle to instance
	Handler * handler;            // pointer to controller


public:
	void changeBrushColor (HWND handle, int_RGB & color)
	{
		colorButton.setBGColor(color.r, color.g, color.b);
	}
	int getBrushColor(int_RGB & color)
	{
		color.r = sliderRed.getPos(); 
		color.g = sliderGreen.getPos(); 
		color.b = sliderBlue.getPos(); 
		return 0;
	}
	int getBrushSize()
	{
		return brushSize.getPos();
	}
public:
	int initControls (HWND handle)
	{
		colorButton.set(handle, IDC_BUTTON_COLOR);
		colorButton.setText(L"This");
		//colorButton.setBGColor(255,255,0);
		//colorButton.hide();

		sliderRed.set(handle, IDC_SLIDER_RED);
		sliderRed.setRange(0, 255);
		sliderRed.setPageSize(25);
		sliderRed.setPos(0);

		sliderGreen.set(handle, IDC_SLIDER_GREEN);
		sliderGreen.setRange(0, 255);
		sliderGreen.setPageSize(25);
		sliderGreen.setPos(0);

		sliderBlue.set(handle, IDC_SLIDER_BLUE);
		sliderBlue.setRange(0, 255);
		sliderBlue.setPageSize(25);
		sliderBlue.setPos(0);

		brushSize.set(handle, IDC_SLIDER_BRUSHSIZE);
		brushSize.setRange(1, 51);  //Brush pixel size is no more than 50
		brushSize.setPageSize(5);
		brushSize.setPos(51);

		return 0;
	}

private:
	// define all the controls here
	//CONTROL::EditBox     colorBox;
	CONTROL::Button		 colorButton ;
	CONTROL::Slider		 sliderRed ;
	CONTROL::Slider		 sliderGreen ;
	CONTROL::Slider		 sliderBlue ;

	CONTROL::Slider		 brushSize ;
	//  CONTROL::Slider		 sliderRed ;
	//	CONTROL::Static		colorStatic;
};

#endif